//
//  YHEventMode.cpp
//  ThunderWarriors
//
//  Created by heinic on 13-3-3.
//
//

#include "YHEventMode.h"


YHEventMode::YHEventMode()
{
    if (s_sharedNotifCenter==NULL) {
        s_sharedNotifCenter = CCNotificationCenter::sharedNotificationCenter();
    }


}

YHEventMode::~YHEventMode()
{
    std::vector<char*>::iterator iter;
    for (iter=events.begin();iter!=events.end();iter++)
    {
        s_sharedNotifCenter->removeObserver(this,*iter);
    }
   

}

bool YHEventMode::isEventEnabled()
{
    return m_bEventEnabled;
}
/// isTouchEnabled setter
void YHEventMode::setEventEnabled(bool enabled)
{
    if (m_bEventEnabled != enabled)
    {
        m_bEventEnabled = enabled;
    }
}

void YHEventMode::registerEvent(SEL_CallFuncO selector, const char *name, cocos2d::CCObject *obj)
{
    if (m_bEventEnabled) {
        char * tmpEvent;
        strcpy(tmpEvent,typeid(this).name());
        s_sharedNotifCenter->addObserver(this, selector, strcat(tmpEvent,name), obj);
        events.push_back(tmpEvent);
    }
    

}

void YHEventMode::dispatchEvent(const char *name, cocos2d::CCObject *obj)
{
    if (m_bEventEnabled) {
        s_sharedNotifCenter->postNotification(name, obj);

    }
   
}

void YHEventMode::removeEvent(const char *name)
{
    if (m_bEventEnabled) {
        s_sharedNotifCenter->removeObserver(this, name);

    }
   
}








